//
// Created on 2025/8/4.
//
// Node APIs are not fully supported. To solve the compilation error of the interface cannot be found,
// please include "napi/native_api.h".

#ifndef MYAPPLICATION_CALLBACKS_H
#define MYAPPLICATION_CALLBACKS_H
#include "i_av_decoder_engine.h"
#include "i_av_encoder_engine.h"
#include "utils.h"

class LambdaAVDecoderCallback: public AVDecodeCallback {
public:
    explicit LambdaAVDecoderCallback(
        std::function<void(uint64_t)> onFrameFunc,
        std::function<void(CodecStatus)> onStatusFunc
    ) : m_onFrameFunc(std::move(onFrameFunc)), m_onStatusFunc(std::move(onStatusFunc)) {LOGI("creat callback");}
    
    void OnDecodeFrame(uint64_t pts) override {
        if (m_onFrameFunc) {
            m_onFrameFunc(pts);
        }
    }
    
    void OnDecodeStatus(CodecStatus status) override {
        if (m_onStatusFunc) {
            m_onStatusFunc(status);
        }
    }
private:
    std::function<void(uint64_t)> m_onFrameFunc;
    std::function<void(CodecStatus)> m_onStatusFunc;
};

class LambdaAVEncoderCallback: public AVEncodeCallback {
public:
    explicit LambdaAVEncoderCallback(
        std::function<void(uint64_t)> onFrameFunc,
        std::function<void(CodecStatus)> onStatusFunc
    ) : m_onFrameFunc(std::move(onFrameFunc)), m_onStatusFunc(std::move(onStatusFunc)) {LOGI("creat callback");}

    void OnEncodeFrame(uint64_t pts) override  {
        if (m_onFrameFunc) {
            m_onFrameFunc(pts);
        }
    }
    
    void OnEncodeStatus(CodecStatus status) override {
        if (m_onStatusFunc) {
            m_onStatusFunc(status);
        }
    }
private:
    std::function<void(uint64_t)> m_onFrameFunc;
    std::function<void(CodecStatus)> m_onStatusFunc;
};


#endif //MYAPPLICATION_CALLBACKS_H
